package cfdt.ldl.db.config;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * <pre>
 * Modify Information:
 * Author       Date          Description
 * ============ ============= ============================
 * ShiHongyi    2021年11月17日 14:29   解决oracle分页总条数问题
 * </pre>
 */
@EnableTransactionManagement
@Configuration
// 统一扫描mapper路径，如cfdt.ldl.db.mapper
@MapperScan("cfdt.**.mapper")
public class MybatisPlusConfig {

    /**
     * 数据库类型，默认是Mysql
     */
    @Value("${mybatis-plus.db-type:mysql}")
    private String dbType;
    
    @Bean
    public PaginationInterceptor paginationInterceptor(){
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();

        // 默认是Mysql数据库方言
        String dialectType = StringUtils.isEmpty(this.dbType) ? DbType.MYSQL.getDb() : this.dbType;
        paginationInterceptor.setDialectType(dialectType);

        return paginationInterceptor;
    }
    
}
